package com.example.demo.util;

import com.example.demo.pojo.User;
import org.joda.time.DateTime;
import org.joda.time.Days;
import org.joda.time.Hours;
import org.joda.time.Seconds;

import javax.servlet.http.HttpServletRequest;
import java.sql.Date;
import java.sql.Timestamp;

public class Tools {



    public static int getHours(Timestamp begin,Timestamp end){
        DateTime dateTime1=new DateTime(begin);
        DateTime dateTime2=new DateTime(end);
        return Hours.hoursBetween(dateTime1,dateTime2).getHours();
    }

    public static int getDays(Timestamp begin,Timestamp end){
        DateTime dateTime1=new DateTime(begin);
        DateTime dateTime2=new DateTime(end);
        return Days.daysBetween(dateTime1,dateTime2).getDays();
    }
    public static int getSeconds(Timestamp begin,Timestamp end){
        DateTime dateTime1=new DateTime(begin);
        DateTime dateTime2=new DateTime(end);
        return Seconds.secondsBetween(dateTime1,dateTime2).getSeconds();
    }
    public static Integer getSessionValue(HttpServletRequest request,String key){
        return  (Integer) request.getSession().getAttribute(key);
    }
}
